package tuanvn.iti.vn;

import java.util.List;
import java.util.Random;

import mrtran.iti.vn.Main;
import mrtran.iti.vn.Main.GameView;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.location.Address;

public class SpriteMonster2 {

	private GameView gameView2;
	private Bitmap bmpMonster2;
	private int widthMonster2;
	private int heightMonster2;
	private static final int BMP_COLUMNS_MONSTER = 7;
	private static final int BMP_ROWS_MONSTER = 2;
	public static int distance2;
	public static int monsterWidth2,widthLuffyMonster2;
	public static int xMonsterCenter2,yMonsterCenter2;
	private List<SpriteMonster2> spriteMonster2;
	int currentFrame2 = 0;
	public static int xSpeedMonster2 =9, ySpeedMonster2 = 0;
	int xMonster2=Main.SCREENWIDTH+Main.SCREENWIDTH/2,yMonster2 = Main.SCREENHEIGHT/2;
	int[] DIRECTION_TO_ANIMATION_MONSTER2 = {0,1};

	
	public SpriteMonster2(GameView gameView2, Bitmap bmpMonster2,List<SpriteMonster2> spriteMonster2) {
		this.gameView2 = gameView2;
		this.bmpMonster2 = bmpMonster2;
		this.distance2 = distance2;
		this.spriteMonster2 = spriteMonster2;
		this.widthMonster2 = bmpMonster2.getWidth() / BMP_COLUMNS_MONSTER;
		this.heightMonster2 = bmpMonster2.getHeight() / BMP_ROWS_MONSTER;	
	}

	private void update() {	
			xMonster2-=xSpeedMonster2;
		    currentFrame2 = ++currentFrame2 % BMP_COLUMNS_MONSTER;	
	
			xMonsterCenter2 = xMonster2+widthMonster2/2;
			yMonsterCenter2 = yMonster2+heightMonster2/2;
			monsterWidth2 = widthMonster2/2;	   
//			
//			if (xMonster2 < gameView2.getWidth()/10-widthMonster2-widthMonster2-widthMonster2) {						
//					spriteMonster2.remove(this);		
//					spriteMonster2.add(new SpriteMonster2(gameView2, bmpMonster2, spriteMonster2));
//			}
		}

	public void onDraw(Canvas canvas) {
		update();
		int srcX2 = currentFrame2 * widthMonster2;
		int srcY2 = getAnimationRowMonster2() * heightMonster2;
		Rect src2 = new Rect(srcX2, srcY2, srcX2 + widthMonster2, srcY2
				+ heightMonster2);
		Rect dst2 = new Rect(xMonster2, yMonster2, xMonster2 + widthMonster2,
				yMonster2 + heightMonster2);
		canvas.drawBitmap(bmpMonster2, src2, dst2, null);
		
	}

	private int getAnimationRowMonster2() {
		double dirDouble = (Math.atan2(xSpeedMonster2, ySpeedMonster2)
				/ (Math.PI / 2) + 2);
		int direction = (int) Math.round(dirDouble) % BMP_ROWS_MONSTER;
		return DIRECTION_TO_ANIMATION_MONSTER2[direction];
	}

}
